from django.db import models

# Create your models here.
        
class Pessoa(models.Model):
    numero_registro = models.CharField(max_length=6,db_index=True)
    class Meta:
        db_table = u'pessoa'
      
class Filial(Pessoa):
    cnpj= models.CharField(max_length=18)
    
    class Meta:
        db_table = u'filial'

class PessoaFisica(Pessoa):
    
    primeiro_nome = models.CharField("Primeiro Nome",max_length=30)
    ultimo_nome = models.CharField(max_length=30)
    is_ativo = models.BooleanField()
    data_registro = models.DateField()
        
    EDUC_CHOICES = (
        ('P', 'Primario'),
        ('S', 'Secundario'),
        ('G', 'Graduacao'),
        
    )
    nivel_educacao = models.CharField(max_length=1, choices=EDUC_CHOICES)
    class Meta:
        db_table = u'pessoafisica'
      
        
class Banco(Pessoa):
    nome = models.CharField(max_length=30)
    nome_curto = models.CharField(max_length=15)
    codigo_compesacao = models.CharField(max_length=15)
    url = models.CharField(max_length=255)
    class Meta:
        db_table = u'banco' 

class ContaBanco(models.Model):
    banco = models.ForeignKey(Banco)
    agencia = models.CharField(max_length=10)
    conta = models.CharField(max_length=10)
    class Meta:
       abstract = True
       

class Cidade(models.Model):
    pais = models.CharField(max_length=50)
    cidade = models.CharField(max_length=50)
    estado = models.CharField(max_length=50)
    class Meta:
        db_table = u'cidade'
    
      
class Ocupacao(models.Model):
    nome = models.CharField(max_length=50)
    class Meta:
        db_table = u'ocupacao'  
    
        
class Telefone(models.Model):
    TYPE_CHOICES = (
        ('C', 'Celular'),
        ('T', 'Comercial'),
        ('F', 'Fax'),
        ('R', 'Residencial'),
    )
    tipo = models.CharField(max_length=1, choices=TYPE_CHOICES)
    ddd = models.CharField(max_length=2)
    numero = models.CharField(max_length=8)
    pessoa = models.ForeignKey(Pessoa)
    class Meta:
        db_table = u'telefone'
    
        
class Endereco(models.Model):
    ADDRESS_CHOICES = (
        ('C', 'Comercial'),
        ('R', 'Residencial'),
    )
    tipo = models.CharField(max_length=1, choices=ADDRESS_CHOICES)
    rua = models.CharField(max_length=40)
    numero = models.IntegerField()
    bairro = models.CharField(max_length=40)
    cep = models.CharField(max_length=9)
    complemento = models.CharField(max_length=20)
    is_pricipalendereco = models.BooleanField()
    pessoa = models.ForeignKey(Pessoa)
    cidade = models.ForeignKey(Cidade)
    email = models.EmailField(max_length=255)
    class Meta:
        db_table = u'endereco'
    
    
class Documento(models.Model):
    pessoa = models.OneToOneField(PessoaFisica,primary_key = True)
    cpf = models.CharField(max_length=14)
    rg = models.CharField(max_length=15)
    rg_expedicao_data = models.DateField(null=True)
    rg_expedicao_local = models.CharField(max_length=20)
    datanascimeto = models.DateField()
    local_nascimento = models.OneToOneField(Cidade)
    ocupacao = models.ForeignKey(Ocupacao)
    TMARITAL_CHOICES = (
         ('S','Solteira'),
         ('C','Casada'),
         ('D','Divociada'),
         ('V','Viuvo'),                    
    )
    
    estadocivil = models.CharField(max_length=1, choices=TMARITAL_CHOICES)
   
    GENDER_CHOICES = (
        ('M', 'Masculino'),
        ('F', 'Feminino'),
    )
    sexo = models.CharField(max_length=1, choices=GENDER_CHOICES)
    observacao = models.TextField()
    
    class Meta:
        db_table = u'documento'
         